package io.kiki.stack.http.feign.SpringMvcContract.loadbalancer;

import io.kiki.stack.http.feign.Response;
import org.springframework.cloud.client.loadbalancer.RetryableStatusCodeException;

import java.io.ByteArrayInputStream;
import java.net.URI;

/**
 * A {@link RetryableStatusCodeException} for {@link Response}s.
 */
public class LoadBalancerResponseStatusCodeException extends RetryableStatusCodeException {

    private final Response response;

    public LoadBalancerResponseStatusCodeException(String serviceId, Response response, byte[] body, URI uri) {
        super(serviceId, response.status(), response, uri);
        this.response = Response.builder().body(new ByteArrayInputStream(body), body.length).headers(response.headers()).reason(response.reason()).status(response.status()).request(response.request()).build();
    }

    @Override
    public Response getResponse() {
        return this.response;
    }

}
